<?php

class BetController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $request = $this->getRequest();
        $event = new Application_Model_DbTable_Event();
    	$empty = new Zend_Validate_NotEmpty(array('integer'));
    	$validators = array('id' => array('Int', $empty));
	    $input = new Zend_Filter_Input(null, $validators);
	    $input->setData($request->getParams());
	    if($input->isValid()){	    	
	    	if($event->CheckDate($input->id)){	    		
	    		$form = new Application_Form_Bet(/*$this->view->url(array('controller' => 'event', 'action' => 'accept'), 'default', true)*/);
	    		$this->view->form = $form;
	    		$this->view->event = $event->GetEventById($input->id);
	    	    if($request->isPost()){
	    	    	if($form->isValid($request->getPost())){
	    	    		$bet = new Application_Model_DbTable_Bet();
	    	    		$bet->SaveBet($input->id, 2, $form->getValue('score_left'), $form->getValue('score_right'));
	    	    	}    		    		
    			}
	    	}
	    	else{
	    		$this->view->message = 'Sorry, but bet date of this event is expired';
	    	}
	    	if($user_id = $this->_helper->Logged->getUserId()){
	    		$this->view->user_id = $user_id;
	    	}	
	    }
	    else{
	    	throw new Zend_Controller_Action_Exception('Invalid input');
	    }
	    
    }
    public function acceptAction()
    {

    }
}